using Crossbow.platform.imote2;
using Crossbow.radio.cc2420;
using Crossbow.lib.utils;
using Crossbow.lib.utils.tos;
using Crossbow.sensor.its400;

namespace Crossbow.app
{
    public class XSensorITS400
    {
        public static void Main()
        {
            const int packet_length = 8;
            const int _interval = 1000;

            Leds _leds = new Leds();
            Its400 _sensor = new Its400();

            byte[] packet = new byte[packet_length];
            ushort counter = 0;
            ushort tmp;

            SerialDump.print("Ready.");     // Application tag

            int index = 0;

            while(true)
            {

                if (counter % 5 == 0)
                {
                    _leds.blueOn();
                }
                else
                {
                    _leds.blueOff();
                }
                if (counter % 5 == 0)
                {
                    tmp = _sensor.TempTIRaw;
                    packet[index++] = (byte)tmp;
                    packet[index++] = (byte)(tmp >> 8);
                    tmp = _sensor.TempSensirionRaw;
                    packet[index++] = (byte)tmp;
                    packet[index++] = (byte)(tmp >> 8);
                    tmp = _sensor.HumidityRaw;
                    packet[index++] = (byte)tmp;
                    packet[index++] = (byte)(tmp >> 8);
                    tmp = _sensor.LightRaw;
                    packet[index++] = (byte)tmp;
                    packet[index++] = (byte)(tmp >> 8);

                    //send it to uart
                    //TosSerialDump.printWithTosHeader(packet);
                    SerialDump.print(packet);
                    index = 0;
                }
                counter++;
                System.Threading.Thread.Sleep(_interval);
            }
        }  // end of Main()
    }
}
